
package com.compuvest.feed

import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

class MailService {

    def session

    def MailService() {
        def props = new Properties()
        props.put("mail.smtp.host", "mail1.compuvest.com")

        session = Session.getDefaultInstance(props, null)
    }

// <editor-fold defaultstate="collapsed" desc="send()">

    def send(subject, content) {

        // Construct the message
        def msg = new MimeMessage(session)
        msg.from = new InternetAddress('webserver@compuvest.com')
        msg.sentDate = new Date()
        msg.subject = subject
        //msg.setRecipient(Message.RecipientType.TO, new InternetAddress('dima@compuvest.com'))
        msg.setRecipient(Message.RecipientType.TO, new InternetAddress('vasil@compuvest.com'))
        //msg.setRecipient(Message.RecipientType.CC, new InternetAddress('vasil@compuvest.com'))
        msg.setHeader('Organization', 'compuvest.com')
        msg.setContent(content, 'text/plain')

        // Send the message
        Transport.send(msg)

    }
// </editor-fold>

}

